#coding=utf-8
import time  
from selenium import webdriver  
from selenium.webdriver.common.action_chains import ActionChains

from bs4 import BeautifulSoup
import math
import random
import numpy as np
import os
import xlrd
import pandas as pd
import requests
import re



'''
def get_html(url):
    headers = {
        'User-Agent':'Mozilla/5.0(Macintosh; Intel Mac OS X 10_11_4)\
        AppleWebKit/537.36(KHTML, like Gecko) Chrome/52 .0.2743. 116 Safari/537.36'
 
    }     #模拟浏览器访问
    response = requests.get(url,headers = headers)       #请求访问网站
    html = response.text       #获取网页源码
    return html                #返回网页源码
 
soup = BeautifulSoup(get_html('https://admin.paypal.com/'), 'lxml')   #初始化BeautifulSoup库,并设置解析器
print(get_html('https://admin.paypal.com'))
for li in soup.find_all(name='li'):         #遍历父节点
        for a in li.find_all(name='a'):     #遍历子节点
            if a.string==None:
                pass
            else:
                print(a.string)      #输出结果
'''





def batch_update(account_id=1314040086950293611, MCC=5331):
        
    driver = webdriver.Chrome(r'C:\Users\guosu\Desktop\Batch Update MCC code in Admin\chromedriver_win32\chromedriver.exe')
    elem = driver.get('https://admin.paypal.com')
    elem = driver.find_element_by_id("id_accountNo")
    elem.send_keys(account_id)
    elem_search = driver.find_element_by_class_name("findUserSearch").click()

    def get_info(account_id=1314040086950293611):
        driver.get('https://admin.paypal.com/cgi-bin/admin?node=service_log_display_account&account_number='+str(account_id)+'&admin_page_by_menu_item=yes')
        driver.execute_script("window.scrollTo(0, (document.body.scrollHeight)/3);")
        status = driver.page_source

        #print(status)
        #print(status.find('Package status:'), status.find('Powered by www.17track.net">Copy details</button>'))

        service_log = status[status.find('Search Attack Results'):status.find('id="attack_next_bottom" value="Next ')]
        filtered_service_log = re.findall(".*<td>(.*)</td>.*",service_log)
        print(str(account_id)+'result is\n')
        for log in filtered_service_log:
            print(log)

    #accounts = [1314040086950293611,1353209486909929348,1502885042634703305,1657895054971016100,1987843796235457675,2157853473188320762,2197985466839445932]
    accounts=[2075215730642855928]

    for account in accounts:
        get_info(account)

    driver.quit()

batch_update()
